from datetime import datetime
def main():
    stop = ''
    for s in iter(input, stop):
        line=s.split()
        year,month=(int(value) for value in line)
        month_day = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
        if (year%4==0 and year%100!=0 )or year%400==0:
            month_day[2]=0
        d=datetime(year,month,month_day[month])
        print(d.isoweekday())
main()
